﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using LcAudit.BPM.Core.Bll;
using LcAudit.Common;
using LcAudit.BPM.Core;
using LcAudit.BPM.Core.Model;
using Omu.ValueInjecter;

namespace LcAudit.BPM.Admin.ashx
{
    /// <summary>
    /// AreaHandler 的摘要说明
    /// </summary>
    public class AreaHandler : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            UserBll.Instance.CheckUserOnlingState();
            int k = 0,isadd=0;
            var json = HttpContext.Current.Request["json"];
            var rpm = new RequestParamModel<Area>(context) { CurrentContext = context, Action = context.Request["action"] };
            if (!string.IsNullOrEmpty(json))
            {
                rpm = JSONhelper.ConvertToObject<RequestParamModel<Area>>(json);
                rpm.CurrentContext = context;
            }
            k = PublicMethod.GetInt(rpm.Request("keyid"));
            isadd = PublicMethod.GetInt(rpm.Request("isadd"));
            switch (rpm.Action)
            {
                case "all":
                    context.Response.Write(AreaBll.Instance.GetAreaTreeJson());
                    break;                
                default:
                    if (isadd == 1)
                    {
                        k = SysVisitor.Instance.UserLevel;
                        context.Response.Write(AreaBll.Instance.GetAreaJsonAdd(k));
                    }
                    else
                        context.Response.Write(AreaBll.Instance.GetAreaJson(k));

                    break;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}